package com.moji.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * 手机号校验工具类
 *
 * @author ccl
 * @date 2021/12/23
 */
public class CheckUtils {
    /**
     * 大陆手机号码11位数，匹配格式：前三位固定格式+后8位任意数
     */
    public static boolean isPhoneLegal(String phone) throws PatternSyntaxException {
        String regex = "^((13[0-9])|(14[05679])|(15([0-3,5-9]))|(16[2567])|(17[01235678])|(18[0-9]|19[1356789]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(phone);
        boolean isMatch = m.matches();
        return isMatch;
    }
    /**
     * 验证输入的邮箱格式是否符合
     * @paramemail
     * @return 是否合法
     */
    public static boolean isEmailLegal(String email) throws PatternSyntaxException {
        Pattern partern = Pattern.compile("[a-zA-Z0-9]+[\\.]{0,1}[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z]+");
        boolean isMatch = partern.matcher(email).matches();
        return isMatch;
    }

    /**
     * 验证输入的url格式是否符合
     * @paramemail
     * @return 是否合法
     */
    public static boolean isUrlLegal(String url) throws PatternSyntaxException {
        Pattern partern = Pattern.compile("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\\\\\\\\\\\\\\\/])+$");
        boolean isMatch = partern.matcher(url).matches();
        return isMatch;
    }
}
